/* 
 * File:   RuleOfThirdsBasedOnValue.cpp
 * Author: guilhermemg
 * 
 * Created on 20 de Fevereiro de 2012, 19:59
 */

#include "RuleOfThirdsBasedOnValue.h"
#include "RuleOfThirds.h"

RuleOfThirdsBasedOnValue::RuleOfThirdsBasedOnValue() : RuleOfThirds() {
    setName("f7");
    setLargeName("f7 - ruleOfThirdsBasedOnValue");
}

RuleOfThirdsBasedOnValue::RuleOfThirdsBasedOnValue(const RuleOfThirdsBasedOnValue& orig) : RuleOfThirds(orig) {
}

RuleOfThirdsBasedOnValue::~RuleOfThirdsBasedOnValue() {
}

void RuleOfThirdsBasedOnValue::calculates() {
    double sum = 0;
    
    for(int i = this->getImage()->width/3; i <= 2*this->getImage()->width/3; i++) {
        uchar* ptr = (uchar*)(this->getImage()->imageData + i*this->getImage()->widthStep);
        for(int j = this->getImage()->height/3; j <= 2*this->getImage()->height/3; j++) {
            sum += ptr[3*j + 2];
        }
    }
    
    sum = (sum/255)*100;
    
    setValue(9*sum/(double)(this->getImage()->height * this->getImage()->width));
}
